package com.zach.common.dao.sqlmapimpl;

import java.util.List;

import org.apache.ibatis.session.RowBounds;
import org.mybatis.spring.support.SqlSessionDaoSupport;

import com.zach.common.dao.UserDao;
import com.zach.common.entity.User;
import com.zach.util.MyBatisUtils;

@SuppressWarnings("unchecked")
public class UserDaoImpl extends SqlSessionDaoSupport implements UserDao {
	private static final long serialVersionUID = -8640452221119564271L;

	@Override
	public User getUserByLoginName(String loginName) {
		return (User) getSqlSession().selectOne("getUserByLoginName", loginName);
	}
	@Override
	public List<User> getUserListByUser(User user) {
		return (List<User>)getSqlSession().selectList("getUserListByUser", user);
	}
	
	@Override
	public List<User> getUserListByUser(User user, Integer pageSize,
			Integer pageNo) {
		RowBounds rb = MyBatisUtils.getRowBounds(pageSize, pageNo);
		return (List<User>)getSqlSession().selectList("getUserListByUser", user,rb);
	}
	@Override
	public void addUser(User user) {
		getSqlSession().insert("addUser", user);
	}
	@Override
	public void updateUserByLoginName(User u) {
		getSqlSession().update("updateUserByLoginName", u);
	}
	
	@Override
	public void updateUserPwdByLoginName(User u) {
		getSqlSession().update("updateUserPwdByLoginName", u);
	}
	
	@Override
	public void deleteUserByLoginName(String loginName) {
		getSqlSession().delete("deleteUserByLoginName", loginName);
	}
	@Override
	public User userLogin(User u) {
		Object obj =  getSqlSession().selectOne("userLogin", u);
		if(null!=obj){
			return (User) obj;
		}else{
			return null;
		}
	}
	
}
